﻿/*
   Author: Tomer Paz
   games.com
   2009
*/

/* Negotiate with other player Dialog
	This dialog will show the alternatives for the player to choose and the other player basic details
*/



package monopoly.GameController.Dialogs {
	
	import monopoly.GameController.Dialogs.IDialog;
	import monopoly.GameController.Dialogs.Templates.*;
	import monopoly.Player.Player;
	import monopoly.Field.Field;
	import monopoly.Localization.*;
	import fl.controls.*;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.EventDispatcher;
	
	public class PlayerNegotiate extends Sprite implements IDialog
		{
		public static const ACTION_PARTNER:int	= 0;
		public static const ACTION_EXCHANGE:int	= 1;
		public static const ACTION_BUY:int		= 2;
		public static const ACTION_PASS:int		= 3;
		
		protected var _chosen_action:uint;
		protected var _myStrings:ILocalLanguage = LocalLanguage.getInstance();
		protected var _field:Field;
		protected var rbuttons:Array = [ _myStrings.DlgNegPartnerOption, _myStrings.DlgNegExchangeOption, _myStrings.DlgNegBuyOption, _myStrings.DlgNegPassOption ];
		protected var rdialog:RadiosDialog;
		
		public function PlayerNegotiate(field:Field)
			{
			_field = field;
			var other_player:Player = _field.Owner;
			var negotiateText:String = _myStrings.DlgNegText(other_player.Name, other_player.Cash);
			
			rdialog = new RadiosDialog(_myStrings.DlgNegLabel, negotiateText, rbuttons);
			rdialog.addEventListener(MouseEvent.CLICK, onPlayerActionDecision);
			
			addChild(rdialog);
			}
		protected function onPlayerActionDecision(e:MouseEvent):void
			{
			if (e.target is Button)
				{
				var dlg:RadiosDialog = e.currentTarget as RadiosDialog;
				var ChosenOption:uint = e.currentTarget.ChosenOption;
				//debug
				trace("[PlayerNegotiate] Chosen option was: " + ChosenOption);
				//end-debug
				
				/* check client has chosen something */
				
				if (BasicDialog.NO_CHOICE == dlg.ChosenOption)
					return;

				
				e.currentTarget.removeEventListener(MouseEvent.CLICK, onPlayerActionDecision);
				e.currentTarget.remove( );
				removeChild(Sprite(e.currentTarget));
				
				/* handle chosen option */
				
				switch(ChosenOption)
					{
					case (ACTION_PARTNER) :				//TODO - to be continued... add another dialog for Partnership?!
						break;
					case (ACTION_EXCHANGE):				//TODO - to be continued... add another dialog for chosing 'my' property from list ?!
						break;
					case (ACTION_BUY)	  :				// Nothing to do !!(?)
						break;
					}
				this._chosen_action = ChosenOption;

				/* signal game controller we are done */

				dispatchEvent(new Event(Event.COMPLETE));
				}
			}

		public function get chosenAction():uint
			{
			return this._chosen_action;
			}
		public function get field():Field
			{
			return this._field;
			}

		}
}